//
//  DateTimeManager.m
//  MingDaEducation
//
//  Created by Herron on 2016/11/23.
//  Copyright © 2016年 Herron. All rights reserved.
//

#import "DateTimeManager.h"

@implementation DateTimeManager

+ (long)currentTimestamp {
    return (long)[[NSDate date] timeIntervalSince1970];
}

+ (NSString *)currentTimeWithDateFormat:(NSString *)dateFormat {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:dateFormat];
    NSString *dateTime = [formatter stringFromDate:[NSDate date]];
    return dateTime;
}

+ (NSString *)dateTimeWithtimestamp:(long)timestamp dateFormat:(NSString *)dateFormat{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    // 此处设置的时间是月日，根据工程的需要进行修改时间显示
    dateFormatter.dateFormat = dateFormat;
    NSDate *date = [[NSDate alloc]initWithTimeIntervalSince1970:timestamp/1000] ;
    //将时间戳数据转换成需要的显示的字符串的样式
    NSString *dateTimeStr = [NSString stringWithFormat:@"%@",[dateFormatter stringFromDate:date]];
    return dateTimeStr;
}

+ (long)timestampWithDateTime:(NSString *)dateTime dateFormat:(NSString *)dateFormat {
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setTimeZone:[NSTimeZone localTimeZone]]; //设置本地时区
    [dateFormatter setDateFormat:dateFormat];
    NSDate *date = [dateFormatter dateFromString:dateTime];
    long timeSp = (long)[date timeIntervalSince1970]*1000;//时间戳
    return timeSp;

}
@end
